package com.zhm.demo.cloud;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;

public class TestConfigServer {

    private static final String SERVER_ADDR = "172.24.73.28:8848";
    private static final String DATA_ID = "example.properties";
    private static final String GROUP = "DEFAULT_GROUP";

    public static ConfigService createConfigService() throws NacosException {
        return NacosFactory.createConfigService(SERVER_ADDR);
    }

    public static void main(String[] args) throws NacosException {
        String content = "123";
        ConfigService configService = TestConfigServer.createConfigService();
        String config = configService.getConfig(DATA_ID, GROUP,1000);

        boolean isPublishOk = configService.publishConfig(DATA_ID, GROUP, content);
        if (isPublishOk) {
            System.out.println("配置发布成功");
        } else {
            System.out.println("配置发布失败");
        }
    }
}
